package edu.msg.jthr.backend.bean;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.msg.jthr.backend.exception.ServiceException;
import edu.msg.jthr.backend.model.JobDescription;
import edu.msg.jthr.backend.repository.exception.RepositoryException;
import edu.msg.jthr.backend.repository.service.JobDescriptionRepository;
import edu.msg.jthr.backend.service.JobDescriptionService;

@Stateless (name = "JobDescriptionServiceBean", mappedName = "ejb/JobDescriptionService")
public class JobDescriptionServiceBean implements JobDescriptionService {

	@EJB
	private JobDescriptionRepository jobDescriptionRepository;
	private static Logger LOG = LoggerFactory
			.getLogger(CandidateServiceBean.class);

	@Override
	public List<JobDescription> getAll() throws ServiceException {
		try {
			return jobDescriptionRepository.getAll();
		} catch (RepositoryException e) {
			LOG.error("Get all jobdesxcriptions error!" + e.getMessage());
			throw new ServiceException("Description getById error!", e);
		}
	}

	@Override
	public JobDescription getById(Long id) throws ServiceException {
		try {
			return jobDescriptionRepository.getById(id);
		} catch (RepositoryException e) {
			LOG.error("Description getById error!" + e.getMessage());
			throw new ServiceException("Description getById error!", e);
		}
	}

	@Override
	public void create(JobDescription obj) throws ServiceException {
		try {
			jobDescriptionRepository.create(obj);
		} catch (RepositoryException e) {
			LOG.error("Description creating failure!" + e.getMessage());
			throw new ServiceException("Description creating failure!",
					e);
		}
	}

	@Override
	public JobDescription update(JobDescription obj) throws ServiceException {
		try {
			return jobDescriptionRepository.update(obj);
		} catch (RepositoryException e) {
			LOG.error("Description update failure!" + e.getMessage());
			throw new ServiceException("Description update failure!", e);
		}
	}

	@Override
	public void delete(JobDescription obj) throws ServiceException {
		try {
			jobDescriptionRepository.delete(obj);
		} catch (RepositoryException e) {
			LOG.error("Description delete failure!" + e.getMessage());
			throw new ServiceException("Description delete failure!", e);
		}
	}

}
